
_cat:     file format elf32-i386


Disassembly of section .text:

00000000 <cat>:

char buf[512];

void
cat(int fd)
{
   0:	55                   	push   %ebp
   1:	89 e5                	mov    %esp,%ebp
   3:	83 ec 28             	sub    $0x28,%esp
  int n;

  while((n = read(fd, buf, sizeof(buf))) > 0)
   6:	eb 1b                	jmp    23 <cat+0x23>
    write(1, buf, n);
   8:	8b 45 f4             	mov    -0xc(%ebp),%eax
   b:	89 44 24 08          	mov    %eax,0x8(%esp)
   f:	c7 44 24 04 60 14 00 	movl   $0x1460,0x4(%esp)
  16:	00 
  17:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  1e:	e8 85 03 00 00       	call   3a8 <write>
void
cat(int fd)
{
  int n;

  while((n = read(fd, buf, sizeof(buf))) > 0)
  23:	c7 44 24 08 00 02 00 	movl   $0x200,0x8(%esp)
  2a:	00 
  2b:	c7 44 24 04 60 14 00 	movl   $0x1460,0x4(%esp)
  32:	00 
  33:	8b 45 08             	mov    0x8(%ebp),%eax
  36:	89 04 24             	mov    %eax,(%esp)
  39:	e8 62 03 00 00       	call   3a0 <read>
  3e:	89 45 f4             	mov    %eax,-0xc(%ebp)
  41:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
  45:	7f c1                	jg     8 <cat+0x8>
    write(1, buf, n);
  if(n < 0){
  47:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
  4b:	79 19                	jns    66 <cat+0x66>
    printf(1, "cat: read error\n");
  4d:	c7 44 24 04 76 0f 00 	movl   $0xf76,0x4(%esp)
  54:	00 
  55:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  5c:	e8 c4 04 00 00       	call   525 <printf>
    exit();
  61:	e8 22 03 00 00       	call   388 <exit>
  }
}
  66:	c9                   	leave  
  67:	c3                   	ret    

00000068 <main>:

int
main(int argc, char *argv[])
{
  68:	55                   	push   %ebp
  69:	89 e5                	mov    %esp,%ebp
  6b:	83 e4 f0             	and    $0xfffffff0,%esp
  6e:	83 ec 20             	sub    $0x20,%esp
  int fd, i;

  if(argc <= 1){
  71:	83 7d 08 01          	cmpl   $0x1,0x8(%ebp)
  75:	7f 11                	jg     88 <main+0x20>
    cat(0);
  77:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
  7e:	e8 7d ff ff ff       	call   0 <cat>
    exit();
  83:	e8 00 03 00 00       	call   388 <exit>
  }

  for(i = 1; i < argc; i++){
  88:	c7 44 24 1c 01 00 00 	movl   $0x1,0x1c(%esp)
  8f:	00 
  90:	eb 79                	jmp    10b <main+0xa3>
    if((fd = open(argv[i], 0)) < 0){
  92:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  96:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
  9d:	8b 45 0c             	mov    0xc(%ebp),%eax
  a0:	01 d0                	add    %edx,%eax
  a2:	8b 00                	mov    (%eax),%eax
  a4:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
  ab:	00 
  ac:	89 04 24             	mov    %eax,(%esp)
  af:	e8 14 03 00 00       	call   3c8 <open>
  b4:	89 44 24 18          	mov    %eax,0x18(%esp)
  b8:	83 7c 24 18 00       	cmpl   $0x0,0x18(%esp)
  bd:	79 2f                	jns    ee <main+0x86>
      printf(1, "cat: cannot open %s\n", argv[i]);
  bf:	8b 44 24 1c          	mov    0x1c(%esp),%eax
  c3:	8d 14 85 00 00 00 00 	lea    0x0(,%eax,4),%edx
  ca:	8b 45 0c             	mov    0xc(%ebp),%eax
  cd:	01 d0                	add    %edx,%eax
  cf:	8b 00                	mov    (%eax),%eax
  d1:	89 44 24 08          	mov    %eax,0x8(%esp)
  d5:	c7 44 24 04 87 0f 00 	movl   $0xf87,0x4(%esp)
  dc:	00 
  dd:	c7 04 24 01 00 00 00 	movl   $0x1,(%esp)
  e4:	e8 3c 04 00 00       	call   525 <printf>
      exit();
  e9:	e8 9a 02 00 00       	call   388 <exit>
    }
    cat(fd);
  ee:	8b 44 24 18          	mov    0x18(%esp),%eax
  f2:	89 04 24             	mov    %eax,(%esp)
  f5:	e8 06 ff ff ff       	call   0 <cat>
    close(fd);
  fa:	8b 44 24 18          	mov    0x18(%esp),%eax
  fe:	89 04 24             	mov    %eax,(%esp)
 101:	e8 aa 02 00 00       	call   3b0 <close>
  if(argc <= 1){
    cat(0);
    exit();
  }

  for(i = 1; i < argc; i++){
 106:	83 44 24 1c 01       	addl   $0x1,0x1c(%esp)
 10b:	8b 44 24 1c          	mov    0x1c(%esp),%eax
 10f:	3b 45 08             	cmp    0x8(%ebp),%eax
 112:	0f 8c 7a ff ff ff    	jl     92 <main+0x2a>
      exit();
    }
    cat(fd);
    close(fd);
  }
  exit();
 118:	e8 6b 02 00 00       	call   388 <exit>
 11d:	66 90                	xchg   %ax,%ax
 11f:	90                   	nop

00000120 <stosb>:
               "cc");
}

static inline void
stosb(void *addr, int data, int cnt)
{
 120:	55                   	push   %ebp
 121:	89 e5                	mov    %esp,%ebp
 123:	57                   	push   %edi
 124:	53                   	push   %ebx
  asm volatile("cld; rep stosb" :
 125:	8b 4d 08             	mov    0x8(%ebp),%ecx
 128:	8b 55 10             	mov    0x10(%ebp),%edx
 12b:	8b 45 0c             	mov    0xc(%ebp),%eax
 12e:	89 cb                	mov    %ecx,%ebx
 130:	89 df                	mov    %ebx,%edi
 132:	89 d1                	mov    %edx,%ecx
 134:	fc                   	cld    
 135:	f3 aa                	rep stos %al,%es:(%edi)
 137:	89 ca                	mov    %ecx,%edx
 139:	89 fb                	mov    %edi,%ebx
 13b:	89 5d 08             	mov    %ebx,0x8(%ebp)
 13e:	89 55 10             	mov    %edx,0x10(%ebp)
               "=D" (addr), "=c" (cnt) :
               "0" (addr), "1" (cnt), "a" (data) :
               "memory", "cc");
}
 141:	5b                   	pop    %ebx
 142:	5f                   	pop    %edi
 143:	5d                   	pop    %ebp
 144:	c3                   	ret    

00000145 <strcpy>:
#include "user.h"
#include "x86.h"

char*
strcpy(char *s, char *t)
{
 145:	55                   	push   %ebp
 146:	89 e5                	mov    %esp,%ebp
 148:	83 ec 10             	sub    $0x10,%esp
  char *os;

  os = s;
 14b:	8b 45 08             	mov    0x8(%ebp),%eax
 14e:	89 45 fc             	mov    %eax,-0x4(%ebp)
  while((*s++ = *t++) != 0)
 151:	90                   	nop
 152:	8b 45 0c             	mov    0xc(%ebp),%eax
 155:	0f b6 10             	movzbl (%eax),%edx
 158:	8b 45 08             	mov    0x8(%ebp),%eax
 15b:	88 10                	mov    %dl,(%eax)
 15d:	8b 45 08             	mov    0x8(%ebp),%eax
 160:	0f b6 00             	movzbl (%eax),%eax
 163:	84 c0                	test   %al,%al
 165:	0f 95 c0             	setne  %al
 168:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 16c:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
 170:	84 c0                	test   %al,%al
 172:	75 de                	jne    152 <strcpy+0xd>
    ;
  return os;
 174:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 177:	c9                   	leave  
 178:	c3                   	ret    

00000179 <strcmp>:

int
strcmp(const char *p, const char *q)
{
 179:	55                   	push   %ebp
 17a:	89 e5                	mov    %esp,%ebp
  while(*p && *p == *q)
 17c:	eb 08                	jmp    186 <strcmp+0xd>
    p++, q++;
 17e:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 182:	83 45 0c 01          	addl   $0x1,0xc(%ebp)
}

int
strcmp(const char *p, const char *q)
{
  while(*p && *p == *q)
 186:	8b 45 08             	mov    0x8(%ebp),%eax
 189:	0f b6 00             	movzbl (%eax),%eax
 18c:	84 c0                	test   %al,%al
 18e:	74 10                	je     1a0 <strcmp+0x27>
 190:	8b 45 08             	mov    0x8(%ebp),%eax
 193:	0f b6 10             	movzbl (%eax),%edx
 196:	8b 45 0c             	mov    0xc(%ebp),%eax
 199:	0f b6 00             	movzbl (%eax),%eax
 19c:	38 c2                	cmp    %al,%dl
 19e:	74 de                	je     17e <strcmp+0x5>
    p++, q++;
  return (uchar)*p - (uchar)*q;
 1a0:	8b 45 08             	mov    0x8(%ebp),%eax
 1a3:	0f b6 00             	movzbl (%eax),%eax
 1a6:	0f b6 d0             	movzbl %al,%edx
 1a9:	8b 45 0c             	mov    0xc(%ebp),%eax
 1ac:	0f b6 00             	movzbl (%eax),%eax
 1af:	0f b6 c0             	movzbl %al,%eax
 1b2:	89 d1                	mov    %edx,%ecx
 1b4:	29 c1                	sub    %eax,%ecx
 1b6:	89 c8                	mov    %ecx,%eax
}
 1b8:	5d                   	pop    %ebp
 1b9:	c3                   	ret    

000001ba <strlen>:

uint
strlen(char *s)
{
 1ba:	55                   	push   %ebp
 1bb:	89 e5                	mov    %esp,%ebp
 1bd:	83 ec 10             	sub    $0x10,%esp
  int n;

  for(n = 0; s[n]; n++)
 1c0:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 1c7:	eb 04                	jmp    1cd <strlen+0x13>
 1c9:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 1cd:	8b 55 fc             	mov    -0x4(%ebp),%edx
 1d0:	8b 45 08             	mov    0x8(%ebp),%eax
 1d3:	01 d0                	add    %edx,%eax
 1d5:	0f b6 00             	movzbl (%eax),%eax
 1d8:	84 c0                	test   %al,%al
 1da:	75 ed                	jne    1c9 <strlen+0xf>
    ;
  return n;
 1dc:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 1df:	c9                   	leave  
 1e0:	c3                   	ret    

000001e1 <memset>:

void*
memset(void *dst, int c, uint n)
{
 1e1:	55                   	push   %ebp
 1e2:	89 e5                	mov    %esp,%ebp
 1e4:	83 ec 0c             	sub    $0xc,%esp
  stosb(dst, c, n);
 1e7:	8b 45 10             	mov    0x10(%ebp),%eax
 1ea:	89 44 24 08          	mov    %eax,0x8(%esp)
 1ee:	8b 45 0c             	mov    0xc(%ebp),%eax
 1f1:	89 44 24 04          	mov    %eax,0x4(%esp)
 1f5:	8b 45 08             	mov    0x8(%ebp),%eax
 1f8:	89 04 24             	mov    %eax,(%esp)
 1fb:	e8 20 ff ff ff       	call   120 <stosb>
  return dst;
 200:	8b 45 08             	mov    0x8(%ebp),%eax
}
 203:	c9                   	leave  
 204:	c3                   	ret    

00000205 <strchr>:

char*
strchr(const char *s, char c)
{
 205:	55                   	push   %ebp
 206:	89 e5                	mov    %esp,%ebp
 208:	83 ec 04             	sub    $0x4,%esp
 20b:	8b 45 0c             	mov    0xc(%ebp),%eax
 20e:	88 45 fc             	mov    %al,-0x4(%ebp)
  for(; *s; s++)
 211:	eb 14                	jmp    227 <strchr+0x22>
    if(*s == c)
 213:	8b 45 08             	mov    0x8(%ebp),%eax
 216:	0f b6 00             	movzbl (%eax),%eax
 219:	3a 45 fc             	cmp    -0x4(%ebp),%al
 21c:	75 05                	jne    223 <strchr+0x1e>
      return (char*)s;
 21e:	8b 45 08             	mov    0x8(%ebp),%eax
 221:	eb 13                	jmp    236 <strchr+0x31>
}

char*
strchr(const char *s, char c)
{
  for(; *s; s++)
 223:	83 45 08 01          	addl   $0x1,0x8(%ebp)
 227:	8b 45 08             	mov    0x8(%ebp),%eax
 22a:	0f b6 00             	movzbl (%eax),%eax
 22d:	84 c0                	test   %al,%al
 22f:	75 e2                	jne    213 <strchr+0xe>
    if(*s == c)
      return (char*)s;
  return 0;
 231:	b8 00 00 00 00       	mov    $0x0,%eax
}
 236:	c9                   	leave  
 237:	c3                   	ret    

00000238 <gets>:

char*
gets(char *buf, int max)
{
 238:	55                   	push   %ebp
 239:	89 e5                	mov    %esp,%ebp
 23b:	83 ec 28             	sub    $0x28,%esp
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 23e:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 245:	eb 46                	jmp    28d <gets+0x55>
    cc = read(0, &c, 1);
 247:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 24e:	00 
 24f:	8d 45 ef             	lea    -0x11(%ebp),%eax
 252:	89 44 24 04          	mov    %eax,0x4(%esp)
 256:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 25d:	e8 3e 01 00 00       	call   3a0 <read>
 262:	89 45 f0             	mov    %eax,-0x10(%ebp)
    if(cc < 1)
 265:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 269:	7e 2f                	jle    29a <gets+0x62>
      break;
    buf[i++] = c;
 26b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 26e:	8b 45 08             	mov    0x8(%ebp),%eax
 271:	01 c2                	add    %eax,%edx
 273:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 277:	88 02                	mov    %al,(%edx)
 279:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
    if(c == '\n' || c == '\r')
 27d:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 281:	3c 0a                	cmp    $0xa,%al
 283:	74 16                	je     29b <gets+0x63>
 285:	0f b6 45 ef          	movzbl -0x11(%ebp),%eax
 289:	3c 0d                	cmp    $0xd,%al
 28b:	74 0e                	je     29b <gets+0x63>
gets(char *buf, int max)
{
  int i, cc;
  char c;

  for(i=0; i+1 < max; ){
 28d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 290:	83 c0 01             	add    $0x1,%eax
 293:	3b 45 0c             	cmp    0xc(%ebp),%eax
 296:	7c af                	jl     247 <gets+0xf>
 298:	eb 01                	jmp    29b <gets+0x63>
    cc = read(0, &c, 1);
    if(cc < 1)
      break;
 29a:	90                   	nop
    buf[i++] = c;
    if(c == '\n' || c == '\r')
      break;
  }
  buf[i] = '\0';
 29b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 29e:	8b 45 08             	mov    0x8(%ebp),%eax
 2a1:	01 d0                	add    %edx,%eax
 2a3:	c6 00 00             	movb   $0x0,(%eax)
  return buf;
 2a6:	8b 45 08             	mov    0x8(%ebp),%eax
}
 2a9:	c9                   	leave  
 2aa:	c3                   	ret    

000002ab <stat>:

int
stat(char *n, struct stat *st)
{
 2ab:	55                   	push   %ebp
 2ac:	89 e5                	mov    %esp,%ebp
 2ae:	83 ec 28             	sub    $0x28,%esp
  int fd;
  int r;

  fd = open(n, O_RDONLY);
 2b1:	c7 44 24 04 00 00 00 	movl   $0x0,0x4(%esp)
 2b8:	00 
 2b9:	8b 45 08             	mov    0x8(%ebp),%eax
 2bc:	89 04 24             	mov    %eax,(%esp)
 2bf:	e8 04 01 00 00       	call   3c8 <open>
 2c4:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(fd < 0)
 2c7:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 2cb:	79 07                	jns    2d4 <stat+0x29>
    return -1;
 2cd:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
 2d2:	eb 23                	jmp    2f7 <stat+0x4c>
  r = fstat(fd, st);
 2d4:	8b 45 0c             	mov    0xc(%ebp),%eax
 2d7:	89 44 24 04          	mov    %eax,0x4(%esp)
 2db:	8b 45 f4             	mov    -0xc(%ebp),%eax
 2de:	89 04 24             	mov    %eax,(%esp)
 2e1:	e8 fa 00 00 00       	call   3e0 <fstat>
 2e6:	89 45 f0             	mov    %eax,-0x10(%ebp)
  close(fd);
 2e9:	8b 45 f4             	mov    -0xc(%ebp),%eax
 2ec:	89 04 24             	mov    %eax,(%esp)
 2ef:	e8 bc 00 00 00       	call   3b0 <close>
  return r;
 2f4:	8b 45 f0             	mov    -0x10(%ebp),%eax
}
 2f7:	c9                   	leave  
 2f8:	c3                   	ret    

000002f9 <atoi>:

int
atoi(const char *s)
{
 2f9:	55                   	push   %ebp
 2fa:	89 e5                	mov    %esp,%ebp
 2fc:	83 ec 10             	sub    $0x10,%esp
  int n;

  n = 0;
 2ff:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
  while('0' <= *s && *s <= '9')
 306:	eb 23                	jmp    32b <atoi+0x32>
    n = n*10 + *s++ - '0';
 308:	8b 55 fc             	mov    -0x4(%ebp),%edx
 30b:	89 d0                	mov    %edx,%eax
 30d:	c1 e0 02             	shl    $0x2,%eax
 310:	01 d0                	add    %edx,%eax
 312:	01 c0                	add    %eax,%eax
 314:	89 c2                	mov    %eax,%edx
 316:	8b 45 08             	mov    0x8(%ebp),%eax
 319:	0f b6 00             	movzbl (%eax),%eax
 31c:	0f be c0             	movsbl %al,%eax
 31f:	01 d0                	add    %edx,%eax
 321:	83 e8 30             	sub    $0x30,%eax
 324:	89 45 fc             	mov    %eax,-0x4(%ebp)
 327:	83 45 08 01          	addl   $0x1,0x8(%ebp)
atoi(const char *s)
{
  int n;

  n = 0;
  while('0' <= *s && *s <= '9')
 32b:	8b 45 08             	mov    0x8(%ebp),%eax
 32e:	0f b6 00             	movzbl (%eax),%eax
 331:	3c 2f                	cmp    $0x2f,%al
 333:	7e 0a                	jle    33f <atoi+0x46>
 335:	8b 45 08             	mov    0x8(%ebp),%eax
 338:	0f b6 00             	movzbl (%eax),%eax
 33b:	3c 39                	cmp    $0x39,%al
 33d:	7e c9                	jle    308 <atoi+0xf>
    n = n*10 + *s++ - '0';
  return n;
 33f:	8b 45 fc             	mov    -0x4(%ebp),%eax
}
 342:	c9                   	leave  
 343:	c3                   	ret    

00000344 <memmove>:

void*
memmove(void *vdst, void *vsrc, int n)
{
 344:	55                   	push   %ebp
 345:	89 e5                	mov    %esp,%ebp
 347:	83 ec 10             	sub    $0x10,%esp
  char *dst, *src;
  
  dst = vdst;
 34a:	8b 45 08             	mov    0x8(%ebp),%eax
 34d:	89 45 fc             	mov    %eax,-0x4(%ebp)
  src = vsrc;
 350:	8b 45 0c             	mov    0xc(%ebp),%eax
 353:	89 45 f8             	mov    %eax,-0x8(%ebp)
  while(n-- > 0)
 356:	eb 13                	jmp    36b <memmove+0x27>
    *dst++ = *src++;
 358:	8b 45 f8             	mov    -0x8(%ebp),%eax
 35b:	0f b6 10             	movzbl (%eax),%edx
 35e:	8b 45 fc             	mov    -0x4(%ebp),%eax
 361:	88 10                	mov    %dl,(%eax)
 363:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 367:	83 45 f8 01          	addl   $0x1,-0x8(%ebp)
{
  char *dst, *src;
  
  dst = vdst;
  src = vsrc;
  while(n-- > 0)
 36b:	83 7d 10 00          	cmpl   $0x0,0x10(%ebp)
 36f:	0f 9f c0             	setg   %al
 372:	83 6d 10 01          	subl   $0x1,0x10(%ebp)
 376:	84 c0                	test   %al,%al
 378:	75 de                	jne    358 <memmove+0x14>
    *dst++ = *src++;
  return vdst;
 37a:	8b 45 08             	mov    0x8(%ebp),%eax
}
 37d:	c9                   	leave  
 37e:	c3                   	ret    
 37f:	90                   	nop

00000380 <fork>:
  name: \
    movl $SYS_ ## name, %eax; \
    int $T_SYSCALL; \
    ret

SYSCALL(fork)
 380:	b8 01 00 00 00       	mov    $0x1,%eax
 385:	cd 40                	int    $0x40
 387:	c3                   	ret    

00000388 <exit>:
SYSCALL(exit)
 388:	b8 02 00 00 00       	mov    $0x2,%eax
 38d:	cd 40                	int    $0x40
 38f:	c3                   	ret    

00000390 <wait>:
SYSCALL(wait)
 390:	b8 03 00 00 00       	mov    $0x3,%eax
 395:	cd 40                	int    $0x40
 397:	c3                   	ret    

00000398 <pipe>:
SYSCALL(pipe)
 398:	b8 04 00 00 00       	mov    $0x4,%eax
 39d:	cd 40                	int    $0x40
 39f:	c3                   	ret    

000003a0 <read>:
SYSCALL(read)
 3a0:	b8 05 00 00 00       	mov    $0x5,%eax
 3a5:	cd 40                	int    $0x40
 3a7:	c3                   	ret    

000003a8 <write>:
SYSCALL(write)
 3a8:	b8 10 00 00 00       	mov    $0x10,%eax
 3ad:	cd 40                	int    $0x40
 3af:	c3                   	ret    

000003b0 <close>:
SYSCALL(close)
 3b0:	b8 15 00 00 00       	mov    $0x15,%eax
 3b5:	cd 40                	int    $0x40
 3b7:	c3                   	ret    

000003b8 <kill>:
SYSCALL(kill)
 3b8:	b8 06 00 00 00       	mov    $0x6,%eax
 3bd:	cd 40                	int    $0x40
 3bf:	c3                   	ret    

000003c0 <exec>:
SYSCALL(exec)
 3c0:	b8 07 00 00 00       	mov    $0x7,%eax
 3c5:	cd 40                	int    $0x40
 3c7:	c3                   	ret    

000003c8 <open>:
SYSCALL(open)
 3c8:	b8 0f 00 00 00       	mov    $0xf,%eax
 3cd:	cd 40                	int    $0x40
 3cf:	c3                   	ret    

000003d0 <mknod>:
SYSCALL(mknod)
 3d0:	b8 11 00 00 00       	mov    $0x11,%eax
 3d5:	cd 40                	int    $0x40
 3d7:	c3                   	ret    

000003d8 <unlink>:
SYSCALL(unlink)
 3d8:	b8 12 00 00 00       	mov    $0x12,%eax
 3dd:	cd 40                	int    $0x40
 3df:	c3                   	ret    

000003e0 <fstat>:
SYSCALL(fstat)
 3e0:	b8 08 00 00 00       	mov    $0x8,%eax
 3e5:	cd 40                	int    $0x40
 3e7:	c3                   	ret    

000003e8 <link>:
SYSCALL(link)
 3e8:	b8 13 00 00 00       	mov    $0x13,%eax
 3ed:	cd 40                	int    $0x40
 3ef:	c3                   	ret    

000003f0 <mkdir>:
SYSCALL(mkdir)
 3f0:	b8 14 00 00 00       	mov    $0x14,%eax
 3f5:	cd 40                	int    $0x40
 3f7:	c3                   	ret    

000003f8 <chdir>:
SYSCALL(chdir)
 3f8:	b8 09 00 00 00       	mov    $0x9,%eax
 3fd:	cd 40                	int    $0x40
 3ff:	c3                   	ret    

00000400 <dup>:
SYSCALL(dup)
 400:	b8 0a 00 00 00       	mov    $0xa,%eax
 405:	cd 40                	int    $0x40
 407:	c3                   	ret    

00000408 <getpid>:
SYSCALL(getpid)
 408:	b8 0b 00 00 00       	mov    $0xb,%eax
 40d:	cd 40                	int    $0x40
 40f:	c3                   	ret    

00000410 <sbrk>:
SYSCALL(sbrk)
 410:	b8 0c 00 00 00       	mov    $0xc,%eax
 415:	cd 40                	int    $0x40
 417:	c3                   	ret    

00000418 <sleep>:
SYSCALL(sleep)
 418:	b8 0d 00 00 00       	mov    $0xd,%eax
 41d:	cd 40                	int    $0x40
 41f:	c3                   	ret    

00000420 <uptime>:
SYSCALL(uptime)
 420:	b8 0e 00 00 00       	mov    $0xe,%eax
 425:	cd 40                	int    $0x40
 427:	c3                   	ret    

00000428 <signal>:

//our addition
SYSCALL(signal)
 428:	b8 1f 00 00 00       	mov    $0x1f,%eax
 42d:	cd 40                	int    $0x40
 42f:	c3                   	ret    

00000430 <sigsend>:
SYSCALL(sigsend)
 430:	b8 20 00 00 00       	mov    $0x20,%eax
 435:	cd 40                	int    $0x40
 437:	c3                   	ret    

00000438 <alarm>:
SYSCALL(alarm)
 438:	b8 21 00 00 00       	mov    $0x21,%eax
 43d:	cd 40                	int    $0x40
 43f:	c3                   	ret    

00000440 <getTicks>:
SYSCALL(getTicks)
 440:	b8 22 00 00 00       	mov    $0x22,%eax
 445:	cd 40                	int    $0x40
 447:	c3                   	ret    

00000448 <putc>:
#include "stat.h"
#include "user.h"

static void
putc(int fd, char c)
{
 448:	55                   	push   %ebp
 449:	89 e5                	mov    %esp,%ebp
 44b:	83 ec 28             	sub    $0x28,%esp
 44e:	8b 45 0c             	mov    0xc(%ebp),%eax
 451:	88 45 f4             	mov    %al,-0xc(%ebp)
  write(fd, &c, 1);
 454:	c7 44 24 08 01 00 00 	movl   $0x1,0x8(%esp)
 45b:	00 
 45c:	8d 45 f4             	lea    -0xc(%ebp),%eax
 45f:	89 44 24 04          	mov    %eax,0x4(%esp)
 463:	8b 45 08             	mov    0x8(%ebp),%eax
 466:	89 04 24             	mov    %eax,(%esp)
 469:	e8 3a ff ff ff       	call   3a8 <write>
}
 46e:	c9                   	leave  
 46f:	c3                   	ret    

00000470 <printint>:

static void
printint(int fd, int xx, int base, int sgn)
{
 470:	55                   	push   %ebp
 471:	89 e5                	mov    %esp,%ebp
 473:	83 ec 48             	sub    $0x48,%esp
  static char digits[] = "0123456789ABCDEF";
  char buf[16];
  int i, neg;
  uint x;

  neg = 0;
 476:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
  if(sgn && xx < 0){
 47d:	83 7d 14 00          	cmpl   $0x0,0x14(%ebp)
 481:	74 17                	je     49a <printint+0x2a>
 483:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 487:	79 11                	jns    49a <printint+0x2a>
    neg = 1;
 489:	c7 45 f0 01 00 00 00 	movl   $0x1,-0x10(%ebp)
    x = -xx;
 490:	8b 45 0c             	mov    0xc(%ebp),%eax
 493:	f7 d8                	neg    %eax
 495:	89 45 ec             	mov    %eax,-0x14(%ebp)
 498:	eb 06                	jmp    4a0 <printint+0x30>
  } else {
    x = xx;
 49a:	8b 45 0c             	mov    0xc(%ebp),%eax
 49d:	89 45 ec             	mov    %eax,-0x14(%ebp)
  }

  i = 0;
 4a0:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
  do{
    buf[i++] = digits[x % base];
 4a7:	8b 4d 10             	mov    0x10(%ebp),%ecx
 4aa:	8b 45 ec             	mov    -0x14(%ebp),%eax
 4ad:	ba 00 00 00 00       	mov    $0x0,%edx
 4b2:	f7 f1                	div    %ecx
 4b4:	89 d0                	mov    %edx,%eax
 4b6:	0f b6 80 18 14 00 00 	movzbl 0x1418(%eax),%eax
 4bd:	8d 4d dc             	lea    -0x24(%ebp),%ecx
 4c0:	8b 55 f4             	mov    -0xc(%ebp),%edx
 4c3:	01 ca                	add    %ecx,%edx
 4c5:	88 02                	mov    %al,(%edx)
 4c7:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
  }while((x /= base) != 0);
 4cb:	8b 55 10             	mov    0x10(%ebp),%edx
 4ce:	89 55 d4             	mov    %edx,-0x2c(%ebp)
 4d1:	8b 45 ec             	mov    -0x14(%ebp),%eax
 4d4:	ba 00 00 00 00       	mov    $0x0,%edx
 4d9:	f7 75 d4             	divl   -0x2c(%ebp)
 4dc:	89 45 ec             	mov    %eax,-0x14(%ebp)
 4df:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 4e3:	75 c2                	jne    4a7 <printint+0x37>
  if(neg)
 4e5:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 4e9:	74 2e                	je     519 <printint+0xa9>
    buf[i++] = '-';
 4eb:	8d 55 dc             	lea    -0x24(%ebp),%edx
 4ee:	8b 45 f4             	mov    -0xc(%ebp),%eax
 4f1:	01 d0                	add    %edx,%eax
 4f3:	c6 00 2d             	movb   $0x2d,(%eax)
 4f6:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)

  while(--i >= 0)
 4fa:	eb 1d                	jmp    519 <printint+0xa9>
    putc(fd, buf[i]);
 4fc:	8d 55 dc             	lea    -0x24(%ebp),%edx
 4ff:	8b 45 f4             	mov    -0xc(%ebp),%eax
 502:	01 d0                	add    %edx,%eax
 504:	0f b6 00             	movzbl (%eax),%eax
 507:	0f be c0             	movsbl %al,%eax
 50a:	89 44 24 04          	mov    %eax,0x4(%esp)
 50e:	8b 45 08             	mov    0x8(%ebp),%eax
 511:	89 04 24             	mov    %eax,(%esp)
 514:	e8 2f ff ff ff       	call   448 <putc>
    buf[i++] = digits[x % base];
  }while((x /= base) != 0);
  if(neg)
    buf[i++] = '-';

  while(--i >= 0)
 519:	83 6d f4 01          	subl   $0x1,-0xc(%ebp)
 51d:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 521:	79 d9                	jns    4fc <printint+0x8c>
    putc(fd, buf[i]);
}
 523:	c9                   	leave  
 524:	c3                   	ret    

00000525 <printf>:

// Print to the given fd. Only understands %d, %x, %p, %s.
void
printf(int fd, char *fmt, ...)
{
 525:	55                   	push   %ebp
 526:	89 e5                	mov    %esp,%ebp
 528:	83 ec 38             	sub    $0x38,%esp
  char *s;
  int c, i, state;
  uint *ap;

  state = 0;
 52b:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  ap = (uint*)(void*)&fmt + 1;
 532:	8d 45 0c             	lea    0xc(%ebp),%eax
 535:	83 c0 04             	add    $0x4,%eax
 538:	89 45 e8             	mov    %eax,-0x18(%ebp)
  for(i = 0; fmt[i]; i++){
 53b:	c7 45 f0 00 00 00 00 	movl   $0x0,-0x10(%ebp)
 542:	e9 7d 01 00 00       	jmp    6c4 <printf+0x19f>
    c = fmt[i] & 0xff;
 547:	8b 55 0c             	mov    0xc(%ebp),%edx
 54a:	8b 45 f0             	mov    -0x10(%ebp),%eax
 54d:	01 d0                	add    %edx,%eax
 54f:	0f b6 00             	movzbl (%eax),%eax
 552:	0f be c0             	movsbl %al,%eax
 555:	25 ff 00 00 00       	and    $0xff,%eax
 55a:	89 45 e4             	mov    %eax,-0x1c(%ebp)
    if(state == 0){
 55d:	83 7d ec 00          	cmpl   $0x0,-0x14(%ebp)
 561:	75 2c                	jne    58f <printf+0x6a>
      if(c == '%'){
 563:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 567:	75 0c                	jne    575 <printf+0x50>
        state = '%';
 569:	c7 45 ec 25 00 00 00 	movl   $0x25,-0x14(%ebp)
 570:	e9 4b 01 00 00       	jmp    6c0 <printf+0x19b>
      } else {
        putc(fd, c);
 575:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 578:	0f be c0             	movsbl %al,%eax
 57b:	89 44 24 04          	mov    %eax,0x4(%esp)
 57f:	8b 45 08             	mov    0x8(%ebp),%eax
 582:	89 04 24             	mov    %eax,(%esp)
 585:	e8 be fe ff ff       	call   448 <putc>
 58a:	e9 31 01 00 00       	jmp    6c0 <printf+0x19b>
      }
    } else if(state == '%'){
 58f:	83 7d ec 25          	cmpl   $0x25,-0x14(%ebp)
 593:	0f 85 27 01 00 00    	jne    6c0 <printf+0x19b>
      if(c == 'd'){
 599:	83 7d e4 64          	cmpl   $0x64,-0x1c(%ebp)
 59d:	75 2d                	jne    5cc <printf+0xa7>
        printint(fd, *ap, 10, 1);
 59f:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5a2:	8b 00                	mov    (%eax),%eax
 5a4:	c7 44 24 0c 01 00 00 	movl   $0x1,0xc(%esp)
 5ab:	00 
 5ac:	c7 44 24 08 0a 00 00 	movl   $0xa,0x8(%esp)
 5b3:	00 
 5b4:	89 44 24 04          	mov    %eax,0x4(%esp)
 5b8:	8b 45 08             	mov    0x8(%ebp),%eax
 5bb:	89 04 24             	mov    %eax,(%esp)
 5be:	e8 ad fe ff ff       	call   470 <printint>
        ap++;
 5c3:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 5c7:	e9 ed 00 00 00       	jmp    6b9 <printf+0x194>
      } else if(c == 'x' || c == 'p'){
 5cc:	83 7d e4 78          	cmpl   $0x78,-0x1c(%ebp)
 5d0:	74 06                	je     5d8 <printf+0xb3>
 5d2:	83 7d e4 70          	cmpl   $0x70,-0x1c(%ebp)
 5d6:	75 2d                	jne    605 <printf+0xe0>
        printint(fd, *ap, 16, 0);
 5d8:	8b 45 e8             	mov    -0x18(%ebp),%eax
 5db:	8b 00                	mov    (%eax),%eax
 5dd:	c7 44 24 0c 00 00 00 	movl   $0x0,0xc(%esp)
 5e4:	00 
 5e5:	c7 44 24 08 10 00 00 	movl   $0x10,0x8(%esp)
 5ec:	00 
 5ed:	89 44 24 04          	mov    %eax,0x4(%esp)
 5f1:	8b 45 08             	mov    0x8(%ebp),%eax
 5f4:	89 04 24             	mov    %eax,(%esp)
 5f7:	e8 74 fe ff ff       	call   470 <printint>
        ap++;
 5fc:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 600:	e9 b4 00 00 00       	jmp    6b9 <printf+0x194>
      } else if(c == 's'){
 605:	83 7d e4 73          	cmpl   $0x73,-0x1c(%ebp)
 609:	75 46                	jne    651 <printf+0x12c>
        s = (char*)*ap;
 60b:	8b 45 e8             	mov    -0x18(%ebp),%eax
 60e:	8b 00                	mov    (%eax),%eax
 610:	89 45 f4             	mov    %eax,-0xc(%ebp)
        ap++;
 613:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
        if(s == 0)
 617:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 61b:	75 27                	jne    644 <printf+0x11f>
          s = "(null)";
 61d:	c7 45 f4 9c 0f 00 00 	movl   $0xf9c,-0xc(%ebp)
        while(*s != 0){
 624:	eb 1e                	jmp    644 <printf+0x11f>
          putc(fd, *s);
 626:	8b 45 f4             	mov    -0xc(%ebp),%eax
 629:	0f b6 00             	movzbl (%eax),%eax
 62c:	0f be c0             	movsbl %al,%eax
 62f:	89 44 24 04          	mov    %eax,0x4(%esp)
 633:	8b 45 08             	mov    0x8(%ebp),%eax
 636:	89 04 24             	mov    %eax,(%esp)
 639:	e8 0a fe ff ff       	call   448 <putc>
          s++;
 63e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 642:	eb 01                	jmp    645 <printf+0x120>
      } else if(c == 's'){
        s = (char*)*ap;
        ap++;
        if(s == 0)
          s = "(null)";
        while(*s != 0){
 644:	90                   	nop
 645:	8b 45 f4             	mov    -0xc(%ebp),%eax
 648:	0f b6 00             	movzbl (%eax),%eax
 64b:	84 c0                	test   %al,%al
 64d:	75 d7                	jne    626 <printf+0x101>
 64f:	eb 68                	jmp    6b9 <printf+0x194>
          putc(fd, *s);
          s++;
        }
      } else if(c == 'c'){
 651:	83 7d e4 63          	cmpl   $0x63,-0x1c(%ebp)
 655:	75 1d                	jne    674 <printf+0x14f>
        putc(fd, *ap);
 657:	8b 45 e8             	mov    -0x18(%ebp),%eax
 65a:	8b 00                	mov    (%eax),%eax
 65c:	0f be c0             	movsbl %al,%eax
 65f:	89 44 24 04          	mov    %eax,0x4(%esp)
 663:	8b 45 08             	mov    0x8(%ebp),%eax
 666:	89 04 24             	mov    %eax,(%esp)
 669:	e8 da fd ff ff       	call   448 <putc>
        ap++;
 66e:	83 45 e8 04          	addl   $0x4,-0x18(%ebp)
 672:	eb 45                	jmp    6b9 <printf+0x194>
      } else if(c == '%'){
 674:	83 7d e4 25          	cmpl   $0x25,-0x1c(%ebp)
 678:	75 17                	jne    691 <printf+0x16c>
        putc(fd, c);
 67a:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 67d:	0f be c0             	movsbl %al,%eax
 680:	89 44 24 04          	mov    %eax,0x4(%esp)
 684:	8b 45 08             	mov    0x8(%ebp),%eax
 687:	89 04 24             	mov    %eax,(%esp)
 68a:	e8 b9 fd ff ff       	call   448 <putc>
 68f:	eb 28                	jmp    6b9 <printf+0x194>
      } else {
        // Unknown % sequence.  Print it to draw attention.
        putc(fd, '%');
 691:	c7 44 24 04 25 00 00 	movl   $0x25,0x4(%esp)
 698:	00 
 699:	8b 45 08             	mov    0x8(%ebp),%eax
 69c:	89 04 24             	mov    %eax,(%esp)
 69f:	e8 a4 fd ff ff       	call   448 <putc>
        putc(fd, c);
 6a4:	8b 45 e4             	mov    -0x1c(%ebp),%eax
 6a7:	0f be c0             	movsbl %al,%eax
 6aa:	89 44 24 04          	mov    %eax,0x4(%esp)
 6ae:	8b 45 08             	mov    0x8(%ebp),%eax
 6b1:	89 04 24             	mov    %eax,(%esp)
 6b4:	e8 8f fd ff ff       	call   448 <putc>
      }
      state = 0;
 6b9:	c7 45 ec 00 00 00 00 	movl   $0x0,-0x14(%ebp)
  int c, i, state;
  uint *ap;

  state = 0;
  ap = (uint*)(void*)&fmt + 1;
  for(i = 0; fmt[i]; i++){
 6c0:	83 45 f0 01          	addl   $0x1,-0x10(%ebp)
 6c4:	8b 55 0c             	mov    0xc(%ebp),%edx
 6c7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 6ca:	01 d0                	add    %edx,%eax
 6cc:	0f b6 00             	movzbl (%eax),%eax
 6cf:	84 c0                	test   %al,%al
 6d1:	0f 85 70 fe ff ff    	jne    547 <printf+0x22>
        putc(fd, c);
      }
      state = 0;
    }
  }
}
 6d7:	c9                   	leave  
 6d8:	c3                   	ret    
 6d9:	66 90                	xchg   %ax,%ax
 6db:	90                   	nop

000006dc <free>:
static Header base;
static Header *freep;

void
free(void *ap)
{
 6dc:	55                   	push   %ebp
 6dd:	89 e5                	mov    %esp,%ebp
 6df:	83 ec 10             	sub    $0x10,%esp
  Header *bp, *p;

  bp = (Header*)ap - 1;
 6e2:	8b 45 08             	mov    0x8(%ebp),%eax
 6e5:	83 e8 08             	sub    $0x8,%eax
 6e8:	89 45 f8             	mov    %eax,-0x8(%ebp)
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 6eb:	a1 48 14 00 00       	mov    0x1448,%eax
 6f0:	89 45 fc             	mov    %eax,-0x4(%ebp)
 6f3:	eb 24                	jmp    719 <free+0x3d>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
 6f5:	8b 45 fc             	mov    -0x4(%ebp),%eax
 6f8:	8b 00                	mov    (%eax),%eax
 6fa:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 6fd:	77 12                	ja     711 <free+0x35>
 6ff:	8b 45 f8             	mov    -0x8(%ebp),%eax
 702:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 705:	77 24                	ja     72b <free+0x4f>
 707:	8b 45 fc             	mov    -0x4(%ebp),%eax
 70a:	8b 00                	mov    (%eax),%eax
 70c:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 70f:	77 1a                	ja     72b <free+0x4f>
free(void *ap)
{
  Header *bp, *p;

  bp = (Header*)ap - 1;
  for(p = freep; !(bp > p && bp < p->s.ptr); p = p->s.ptr)
 711:	8b 45 fc             	mov    -0x4(%ebp),%eax
 714:	8b 00                	mov    (%eax),%eax
 716:	89 45 fc             	mov    %eax,-0x4(%ebp)
 719:	8b 45 f8             	mov    -0x8(%ebp),%eax
 71c:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 71f:	76 d4                	jbe    6f5 <free+0x19>
 721:	8b 45 fc             	mov    -0x4(%ebp),%eax
 724:	8b 00                	mov    (%eax),%eax
 726:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 729:	76 ca                	jbe    6f5 <free+0x19>
    if(p >= p->s.ptr && (bp > p || bp < p->s.ptr))
      break;
  if(bp + bp->s.size == p->s.ptr){
 72b:	8b 45 f8             	mov    -0x8(%ebp),%eax
 72e:	8b 40 04             	mov    0x4(%eax),%eax
 731:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 738:	8b 45 f8             	mov    -0x8(%ebp),%eax
 73b:	01 c2                	add    %eax,%edx
 73d:	8b 45 fc             	mov    -0x4(%ebp),%eax
 740:	8b 00                	mov    (%eax),%eax
 742:	39 c2                	cmp    %eax,%edx
 744:	75 24                	jne    76a <free+0x8e>
    bp->s.size += p->s.ptr->s.size;
 746:	8b 45 f8             	mov    -0x8(%ebp),%eax
 749:	8b 50 04             	mov    0x4(%eax),%edx
 74c:	8b 45 fc             	mov    -0x4(%ebp),%eax
 74f:	8b 00                	mov    (%eax),%eax
 751:	8b 40 04             	mov    0x4(%eax),%eax
 754:	01 c2                	add    %eax,%edx
 756:	8b 45 f8             	mov    -0x8(%ebp),%eax
 759:	89 50 04             	mov    %edx,0x4(%eax)
    bp->s.ptr = p->s.ptr->s.ptr;
 75c:	8b 45 fc             	mov    -0x4(%ebp),%eax
 75f:	8b 00                	mov    (%eax),%eax
 761:	8b 10                	mov    (%eax),%edx
 763:	8b 45 f8             	mov    -0x8(%ebp),%eax
 766:	89 10                	mov    %edx,(%eax)
 768:	eb 0a                	jmp    774 <free+0x98>
  } else
    bp->s.ptr = p->s.ptr;
 76a:	8b 45 fc             	mov    -0x4(%ebp),%eax
 76d:	8b 10                	mov    (%eax),%edx
 76f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 772:	89 10                	mov    %edx,(%eax)
  if(p + p->s.size == bp){
 774:	8b 45 fc             	mov    -0x4(%ebp),%eax
 777:	8b 40 04             	mov    0x4(%eax),%eax
 77a:	8d 14 c5 00 00 00 00 	lea    0x0(,%eax,8),%edx
 781:	8b 45 fc             	mov    -0x4(%ebp),%eax
 784:	01 d0                	add    %edx,%eax
 786:	3b 45 f8             	cmp    -0x8(%ebp),%eax
 789:	75 20                	jne    7ab <free+0xcf>
    p->s.size += bp->s.size;
 78b:	8b 45 fc             	mov    -0x4(%ebp),%eax
 78e:	8b 50 04             	mov    0x4(%eax),%edx
 791:	8b 45 f8             	mov    -0x8(%ebp),%eax
 794:	8b 40 04             	mov    0x4(%eax),%eax
 797:	01 c2                	add    %eax,%edx
 799:	8b 45 fc             	mov    -0x4(%ebp),%eax
 79c:	89 50 04             	mov    %edx,0x4(%eax)
    p->s.ptr = bp->s.ptr;
 79f:	8b 45 f8             	mov    -0x8(%ebp),%eax
 7a2:	8b 10                	mov    (%eax),%edx
 7a4:	8b 45 fc             	mov    -0x4(%ebp),%eax
 7a7:	89 10                	mov    %edx,(%eax)
 7a9:	eb 08                	jmp    7b3 <free+0xd7>
  } else
    p->s.ptr = bp;
 7ab:	8b 45 fc             	mov    -0x4(%ebp),%eax
 7ae:	8b 55 f8             	mov    -0x8(%ebp),%edx
 7b1:	89 10                	mov    %edx,(%eax)
  freep = p;
 7b3:	8b 45 fc             	mov    -0x4(%ebp),%eax
 7b6:	a3 48 14 00 00       	mov    %eax,0x1448
}
 7bb:	c9                   	leave  
 7bc:	c3                   	ret    

000007bd <morecore>:

static Header*
morecore(uint nu)
{
 7bd:	55                   	push   %ebp
 7be:	89 e5                	mov    %esp,%ebp
 7c0:	83 ec 28             	sub    $0x28,%esp
  char *p;
  Header *hp;

  if(nu < 4096)
 7c3:	81 7d 08 ff 0f 00 00 	cmpl   $0xfff,0x8(%ebp)
 7ca:	77 07                	ja     7d3 <morecore+0x16>
    nu = 4096;
 7cc:	c7 45 08 00 10 00 00 	movl   $0x1000,0x8(%ebp)
  p = sbrk(nu * sizeof(Header));
 7d3:	8b 45 08             	mov    0x8(%ebp),%eax
 7d6:	c1 e0 03             	shl    $0x3,%eax
 7d9:	89 04 24             	mov    %eax,(%esp)
 7dc:	e8 2f fc ff ff       	call   410 <sbrk>
 7e1:	89 45 f4             	mov    %eax,-0xc(%ebp)
  if(p == (char*)-1)
 7e4:	83 7d f4 ff          	cmpl   $0xffffffff,-0xc(%ebp)
 7e8:	75 07                	jne    7f1 <morecore+0x34>
    return 0;
 7ea:	b8 00 00 00 00       	mov    $0x0,%eax
 7ef:	eb 22                	jmp    813 <morecore+0x56>
  hp = (Header*)p;
 7f1:	8b 45 f4             	mov    -0xc(%ebp),%eax
 7f4:	89 45 f0             	mov    %eax,-0x10(%ebp)
  hp->s.size = nu;
 7f7:	8b 45 f0             	mov    -0x10(%ebp),%eax
 7fa:	8b 55 08             	mov    0x8(%ebp),%edx
 7fd:	89 50 04             	mov    %edx,0x4(%eax)
  free((void*)(hp + 1));
 800:	8b 45 f0             	mov    -0x10(%ebp),%eax
 803:	83 c0 08             	add    $0x8,%eax
 806:	89 04 24             	mov    %eax,(%esp)
 809:	e8 ce fe ff ff       	call   6dc <free>
  return freep;
 80e:	a1 48 14 00 00       	mov    0x1448,%eax
}
 813:	c9                   	leave  
 814:	c3                   	ret    

00000815 <malloc>:

void*
malloc(uint nbytes)
{
 815:	55                   	push   %ebp
 816:	89 e5                	mov    %esp,%ebp
 818:	83 ec 28             	sub    $0x28,%esp
  Header *p, *prevp;
  uint nunits;

  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
 81b:	8b 45 08             	mov    0x8(%ebp),%eax
 81e:	83 c0 07             	add    $0x7,%eax
 821:	c1 e8 03             	shr    $0x3,%eax
 824:	83 c0 01             	add    $0x1,%eax
 827:	89 45 ec             	mov    %eax,-0x14(%ebp)
  if((prevp = freep) == 0){
 82a:	a1 48 14 00 00       	mov    0x1448,%eax
 82f:	89 45 f0             	mov    %eax,-0x10(%ebp)
 832:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 836:	75 23                	jne    85b <malloc+0x46>
    base.s.ptr = freep = prevp = &base;
 838:	c7 45 f0 40 14 00 00 	movl   $0x1440,-0x10(%ebp)
 83f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 842:	a3 48 14 00 00       	mov    %eax,0x1448
 847:	a1 48 14 00 00       	mov    0x1448,%eax
 84c:	a3 40 14 00 00       	mov    %eax,0x1440
    base.s.size = 0;
 851:	c7 05 44 14 00 00 00 	movl   $0x0,0x1444
 858:	00 00 00 
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 85b:	8b 45 f0             	mov    -0x10(%ebp),%eax
 85e:	8b 00                	mov    (%eax),%eax
 860:	89 45 f4             	mov    %eax,-0xc(%ebp)
    if(p->s.size >= nunits){
 863:	8b 45 f4             	mov    -0xc(%ebp),%eax
 866:	8b 40 04             	mov    0x4(%eax),%eax
 869:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 86c:	72 4d                	jb     8bb <malloc+0xa6>
      if(p->s.size == nunits)
 86e:	8b 45 f4             	mov    -0xc(%ebp),%eax
 871:	8b 40 04             	mov    0x4(%eax),%eax
 874:	3b 45 ec             	cmp    -0x14(%ebp),%eax
 877:	75 0c                	jne    885 <malloc+0x70>
        prevp->s.ptr = p->s.ptr;
 879:	8b 45 f4             	mov    -0xc(%ebp),%eax
 87c:	8b 10                	mov    (%eax),%edx
 87e:	8b 45 f0             	mov    -0x10(%ebp),%eax
 881:	89 10                	mov    %edx,(%eax)
 883:	eb 26                	jmp    8ab <malloc+0x96>
      else {
        p->s.size -= nunits;
 885:	8b 45 f4             	mov    -0xc(%ebp),%eax
 888:	8b 40 04             	mov    0x4(%eax),%eax
 88b:	89 c2                	mov    %eax,%edx
 88d:	2b 55 ec             	sub    -0x14(%ebp),%edx
 890:	8b 45 f4             	mov    -0xc(%ebp),%eax
 893:	89 50 04             	mov    %edx,0x4(%eax)
        p += p->s.size;
 896:	8b 45 f4             	mov    -0xc(%ebp),%eax
 899:	8b 40 04             	mov    0x4(%eax),%eax
 89c:	c1 e0 03             	shl    $0x3,%eax
 89f:	01 45 f4             	add    %eax,-0xc(%ebp)
        p->s.size = nunits;
 8a2:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8a5:	8b 55 ec             	mov    -0x14(%ebp),%edx
 8a8:	89 50 04             	mov    %edx,0x4(%eax)
      }
      freep = prevp;
 8ab:	8b 45 f0             	mov    -0x10(%ebp),%eax
 8ae:	a3 48 14 00 00       	mov    %eax,0x1448
      return (void*)(p + 1);
 8b3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8b6:	83 c0 08             	add    $0x8,%eax
 8b9:	eb 38                	jmp    8f3 <malloc+0xde>
    }
    if(p == freep)
 8bb:	a1 48 14 00 00       	mov    0x1448,%eax
 8c0:	39 45 f4             	cmp    %eax,-0xc(%ebp)
 8c3:	75 1b                	jne    8e0 <malloc+0xcb>
      if((p = morecore(nunits)) == 0)
 8c5:	8b 45 ec             	mov    -0x14(%ebp),%eax
 8c8:	89 04 24             	mov    %eax,(%esp)
 8cb:	e8 ed fe ff ff       	call   7bd <morecore>
 8d0:	89 45 f4             	mov    %eax,-0xc(%ebp)
 8d3:	83 7d f4 00          	cmpl   $0x0,-0xc(%ebp)
 8d7:	75 07                	jne    8e0 <malloc+0xcb>
        return 0;
 8d9:	b8 00 00 00 00       	mov    $0x0,%eax
 8de:	eb 13                	jmp    8f3 <malloc+0xde>
  nunits = (nbytes + sizeof(Header) - 1)/sizeof(Header) + 1;
  if((prevp = freep) == 0){
    base.s.ptr = freep = prevp = &base;
    base.s.size = 0;
  }
  for(p = prevp->s.ptr; ; prevp = p, p = p->s.ptr){
 8e0:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8e3:	89 45 f0             	mov    %eax,-0x10(%ebp)
 8e6:	8b 45 f4             	mov    -0xc(%ebp),%eax
 8e9:	8b 00                	mov    (%eax),%eax
 8eb:	89 45 f4             	mov    %eax,-0xc(%ebp)
      return (void*)(p + 1);
    }
    if(p == freep)
      if((p = morecore(nunits)) == 0)
        return 0;
  }
 8ee:	e9 70 ff ff ff       	jmp    863 <malloc+0x4e>
}
 8f3:	c9                   	leave  
 8f4:	c3                   	ret    
 8f5:	66 90                	xchg   %ax,%ax
 8f7:	90                   	nop

000008f8 <uthread_init>:
int c_thread = 0;

// task 2.2

void uthread_init()
{
 8f8:	55                   	push   %ebp
 8f9:	89 e5                	mov    %esp,%ebp
 8fb:	83 ec 28             	sub    $0x28,%esp

	int i;
	ttable[0].tid = 0;
 8fe:	c7 05 60 16 00 00 00 	movl   $0x0,0x1660
 905:	00 00 00 
	STORE_ESP(ttable[0].esp);
 908:	89 e0                	mov    %esp,%eax
 90a:	a3 64 16 00 00       	mov    %eax,0x1664
	STORE_EBP(ttable[0].ebp);
 90f:	89 e8                	mov    %ebp,%eax
 911:	a3 68 16 00 00       	mov    %eax,0x1668
	ttable[0].state = T_RUNNING;
 916:	c7 05 70 16 00 00 01 	movl   $0x1,0x1670
 91d:	00 00 00 
	ttable[0].wait_num = 0;
 920:	c7 05 74 17 00 00 00 	movl   $0x0,0x1774
 927:	00 00 00 
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 92a:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 931:	eb 2c                	jmp    95f <uthread_init+0x67>
	{
		ttable[i].tid = i;
 933:	8b 45 f4             	mov    -0xc(%ebp),%eax
 936:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 93c:	8d 90 60 16 00 00    	lea    0x1660(%eax),%edx
 942:	8b 45 f4             	mov    -0xc(%ebp),%eax
 945:	89 02                	mov    %eax,(%edx)
		ttable[i].state = T_FREE;
 947:	8b 45 f4             	mov    -0xc(%ebp),%eax
 94a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 950:	05 70 16 00 00       	add    $0x1670,%eax
 955:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	STORE_ESP(ttable[0].esp);
	STORE_EBP(ttable[0].ebp);
	ttable[0].state = T_RUNNING;
	ttable[0].wait_num = 0;
	//initialize all other slots to FREE and assign TIDs for future use
	for (i = 1; i < MAX_THREAD; i ++)
 95b:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 95f:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 963:	7e ce                	jle    933 <uthread_init+0x3b>
	{
		ttable[i].tid = i;
		ttable[i].state = T_FREE;
	}
	signal(SIGALRM, uthread_yield);
 965:	c7 44 24 04 eb 0b 00 	movl   $0xbeb,0x4(%esp)
 96c:	00 
 96d:	c7 04 24 0e 00 00 00 	movl   $0xe,(%esp)
 974:	e8 af fa ff ff       	call   428 <signal>
	alarm(THREAD_QUANTA);
 979:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 980:	e8 b3 fa ff ff       	call   438 <alarm>
}
 985:	c9                   	leave  
 986:	c3                   	ret    

00000987 <uthread_create>:

// task 2.3

int uthread_create(void (*start_func)(void *), void*arg)
{
 987:	55                   	push   %ebp
 988:	89 e5                	mov    %esp,%ebp
 98a:	83 ec 28             	sub    $0x28,%esp
	int i;
	int ticks;
	asm("pusha");
 98d:	60                   	pusha  
	ticks = getTicks();
 98e:	e8 ad fa ff ff       	call   440 <getTicks>
 993:	89 45 f0             	mov    %eax,-0x10(%ebp)
	alarm(0);
 996:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 99d:	e8 96 fa ff ff       	call   438 <alarm>
	asm("popa");
 9a2:	61                   	popa   
	for (i = 0; i < MAX_THREAD; i++)
 9a3:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 9aa:	e9 02 01 00 00       	jmp    ab1 <uthread_create+0x12a>
	{
		if (ttable[i].state == T_FREE)
 9af:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9b2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9b8:	05 70 16 00 00       	add    $0x1670,%eax
 9bd:	8b 00                	mov    (%eax),%eax
 9bf:	85 c0                	test   %eax,%eax
 9c1:	0f 85 e6 00 00 00    	jne    aad <uthread_create+0x126>
		{	
			//allocate a stack for the new thread
			if ((ttable[i].stack = malloc(STACK_SIZE)) < 0)
 9c7:	c7 04 24 00 10 00 00 	movl   $0x1000,(%esp)
 9ce:	e8 42 fe ff ff       	call   815 <malloc>
 9d3:	8b 55 f4             	mov    -0xc(%ebp),%edx
 9d6:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 9dc:	81 c2 60 16 00 00    	add    $0x1660,%edx
 9e2:	89 42 0c             	mov    %eax,0xc(%edx)
			{
				alarm(ticks);
				return -1;
			}
			LOAD_ESP(ttable[i].stack + STACK_SIZE);
 9e5:	8b 45 f4             	mov    -0xc(%ebp),%eax
 9e8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 9ee:	05 60 16 00 00       	add    $0x1660,%eax
 9f3:	8b 40 0c             	mov    0xc(%eax),%eax
 9f6:	05 00 10 00 00       	add    $0x1000,%eax
 9fb:	89 c4                	mov    %eax,%esp
			PUSH(arg);
 9fd:	8b 45 0c             	mov    0xc(%ebp),%eax
 a00:	89 c7                	mov    %eax,%edi
 a02:	57                   	push   %edi
			PUSH(uthread_exit);
 a03:	b8 71 0c 00 00       	mov    $0xc71,%eax
 a08:	89 c7                	mov    %eax,%edi
 a0a:	57                   	push   %edi
			PUSH(start_func);
 a0b:	8b 45 08             	mov    0x8(%ebp),%eax
 a0e:	89 c7                	mov    %eax,%edi
 a10:	57                   	push   %edi
			//added for the first "pop ebp"
			PUSH(0);
 a11:	b8 00 00 00 00       	mov    $0x0,%eax
 a16:	89 c7                	mov    %eax,%edi
 a18:	57                   	push   %edi
			STORE_ESP(ttable[i].ebp);
 a19:	89 e0                	mov    %esp,%eax
 a1b:	8b 55 f4             	mov    -0xc(%ebp),%edx
 a1e:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 a24:	81 c2 60 16 00 00    	add    $0x1660,%edx
 a2a:	89 42 08             	mov    %eax,0x8(%edx)
			ttable[i].esp = ttable[i].ebp;
 a2d:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a30:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a36:	05 60 16 00 00       	add    $0x1660,%eax
 a3b:	8b 40 08             	mov    0x8(%eax),%eax
 a3e:	8b 55 f4             	mov    -0xc(%ebp),%edx
 a41:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 a47:	81 c2 60 16 00 00    	add    $0x1660,%edx
 a4d:	89 42 04             	mov    %eax,0x4(%edx)
			//set esp to current thread's esp
			LOAD_ESP(ttable[c_thread].esp);
 a50:	a1 4c 14 00 00       	mov    0x144c,%eax
 a55:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a5b:	05 60 16 00 00       	add    $0x1660,%eax
 a60:	8b 40 04             	mov    0x4(%eax),%eax
 a63:	89 c4                	mov    %eax,%esp
			ttable[i].state = T_RUNNABLE;
 a65:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a68:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a6e:	05 70 16 00 00       	add    $0x1670,%eax
 a73:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
			ttable[i].wait_num = 0;
 a79:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a7c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 a82:	05 70 17 00 00       	add    $0x1770,%eax
 a87:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
			asm("pusha");
 a8e:	60                   	pusha  
			alarm(ticks);
 a8f:	8b 45 f0             	mov    -0x10(%ebp),%eax
 a92:	89 04 24             	mov    %eax,(%esp)
 a95:	e8 9e f9 ff ff       	call   438 <alarm>
			asm("popa");
 a9a:	61                   	popa   
			return ttable[i].tid;
 a9b:	8b 45 f4             	mov    -0xc(%ebp),%eax
 a9e:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 aa4:	05 60 16 00 00       	add    $0x1660,%eax
 aa9:	8b 00                	mov    (%eax),%eax
 aab:	eb 1e                	jmp    acb <uthread_create+0x144>
	int ticks;
	asm("pusha");
	ticks = getTicks();
	alarm(0);
	asm("popa");
	for (i = 0; i < MAX_THREAD; i++)
 aad:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 ab1:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 ab5:	0f 8e f4 fe ff ff    	jle    9af <uthread_create+0x28>
			asm("popa");
			return ttable[i].tid;
			
		}
	}
	alarm(ticks);
 abb:	8b 45 f0             	mov    -0x10(%ebp),%eax
 abe:	89 04 24             	mov    %eax,(%esp)
 ac1:	e8 72 f9 ff ff       	call   438 <alarm>
	//failed - no free thread to use
	return -1;
 ac6:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 acb:	c9                   	leave  
 acc:	c3                   	ret    

00000acd <safe_exit>:

// task 2.4


void safe_exit()
{
 acd:	55                   	push   %ebp
 ace:	89 e5                	mov    %esp,%ebp
 ad0:	83 ec 28             	sub    $0x28,%esp
 ad3:	eb 01                	jmp    ad6 <safe_exit+0x9>
			}
		}
		if (tid == MAX_THREAD){
			exit();
		}
	}
 ad5:	90                   	nop
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 ad6:	c7 45 f4 01 00 00 00 	movl   $0x1,-0xc(%ebp)
 add:	eb 25                	jmp    b04 <safe_exit+0x37>
		{
			if (ttable[tid].state != T_FREE){
 adf:	8b 45 f4             	mov    -0xc(%ebp),%eax
 ae2:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ae8:	05 70 16 00 00       	add    $0x1670,%eax
 aed:	8b 00                	mov    (%eax),%eax
 aef:	85 c0                	test   %eax,%eax
 af1:	74 0d                	je     b00 <safe_exit+0x33>
				uthread_join(tid);
 af3:	8b 45 f4             	mov    -0xc(%ebp),%eax
 af6:	89 04 24             	mov    %eax,(%esp)
 af9:	e8 1d 02 00 00       	call   d1b <uthread_join>
				break;
 afe:	eb 0a                	jmp    b0a <safe_exit+0x3d>
void safe_exit()
{
	int tid;
	while (1)
	{
		for (tid = 1; tid< MAX_THREAD; tid++)
 b00:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 b04:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 b08:	7e d5                	jle    adf <safe_exit+0x12>
			if (ttable[tid].state != T_FREE){
				uthread_join(tid);
				break;
			}
		}
		if (tid == MAX_THREAD){
 b0a:	83 7d f4 40          	cmpl   $0x40,-0xc(%ebp)
 b0e:	75 c5                	jne    ad5 <safe_exit+0x8>
			exit();
 b10:	e8 73 f8 ff ff       	call   388 <exit>

00000b15 <uthread_switch>:
		}
	}
}

void uthread_switch()
{
 b15:	55                   	push   %ebp
 b16:	89 e5                	mov    %esp,%ebp
 b18:	83 ec 28             	sub    $0x28,%esp
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;
 b1b:	a1 4c 14 00 00       	mov    0x144c,%eax
 b20:	8d 50 01             	lea    0x1(%eax),%edx
 b23:	89 d0                	mov    %edx,%eax
 b25:	c1 f8 1f             	sar    $0x1f,%eax
 b28:	c1 e8 1a             	shr    $0x1a,%eax
 b2b:	01 c2                	add    %eax,%edx
 b2d:	83 e2 3f             	and    $0x3f,%edx
 b30:	89 d1                	mov    %edx,%ecx
 b32:	29 c1                	sub    %eax,%ecx
 b34:	89 c8                	mov    %ecx,%eax
 b36:	89 45 f0             	mov    %eax,-0x10(%ebp)

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 b39:	c7 45 f4 00 00 00 00 	movl   $0x0,-0xc(%ebp)
 b40:	eb 20                	jmp    b62 <uthread_switch+0x4d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
 b42:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b45:	8d 50 01             	lea    0x1(%eax),%edx
 b48:	89 d0                	mov    %edx,%eax
 b4a:	c1 f8 1f             	sar    $0x1f,%eax
 b4d:	c1 e8 1a             	shr    $0x1a,%eax
 b50:	01 c2                	add    %eax,%edx
 b52:	83 e2 3f             	and    $0x3f,%edx
 b55:	89 d1                	mov    %edx,%ecx
 b57:	29 c1                	sub    %eax,%ecx
 b59:	89 c8                	mov    %ecx,%eax
 b5b:	89 45 f0             	mov    %eax,-0x10(%ebp)
{
	int i;
	int n_thread = (c_thread + 1) % MAX_THREAD;

	//finding a runnable thread
	for (i = 0; ttable[n_thread].state != T_RUNNABLE && i < MAX_THREAD; i++)
 b5e:	83 45 f4 01          	addl   $0x1,-0xc(%ebp)
 b62:	8b 45 f0             	mov    -0x10(%ebp),%eax
 b65:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 b6b:	05 70 16 00 00       	add    $0x1670,%eax
 b70:	8b 00                	mov    (%eax),%eax
 b72:	83 f8 02             	cmp    $0x2,%eax
 b75:	74 06                	je     b7d <uthread_switch+0x68>
 b77:	83 7d f4 3f          	cmpl   $0x3f,-0xc(%ebp)
 b7b:	7e c5                	jle    b42 <uthread_switch+0x2d>
	{
		n_thread = (n_thread + 1) % MAX_THREAD;
	}
	STORE_ESP(ttable[c_thread].esp);
 b7d:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 b83:	89 e0                	mov    %esp,%eax
 b85:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 b8b:	81 c2 60 16 00 00    	add    $0x1660,%edx
 b91:	89 42 04             	mov    %eax,0x4(%edx)
	STORE_EBP(ttable[c_thread].ebp);
 b94:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 b9a:	89 e8                	mov    %ebp,%eax
 b9c:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 ba2:	81 c2 60 16 00 00    	add    $0x1660,%edx
 ba8:	89 42 08             	mov    %eax,0x8(%edx)
	c_thread = n_thread;
 bab:	8b 45 f0             	mov    -0x10(%ebp),%eax
 bae:	a3 4c 14 00 00       	mov    %eax,0x144c
	LOAD_EBP(ttable[c_thread].ebp);
 bb3:	a1 4c 14 00 00       	mov    0x144c,%eax
 bb8:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bbe:	05 60 16 00 00       	add    $0x1660,%eax
 bc3:	8b 40 08             	mov    0x8(%eax),%eax
 bc6:	89 c5                	mov    %eax,%ebp
	LOAD_ESP(ttable[c_thread].esp);
 bc8:	a1 4c 14 00 00       	mov    0x144c,%eax
 bcd:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 bd3:	05 60 16 00 00       	add    $0x1660,%eax
 bd8:	8b 40 04             	mov    0x4(%eax),%eax
 bdb:	89 c4                	mov    %eax,%esp
	alarm(THREAD_QUANTA);
 bdd:	c7 04 24 05 00 00 00 	movl   $0x5,(%esp)
 be4:	e8 4f f8 ff ff       	call   438 <alarm>
}
 be9:	c9                   	leave  
 bea:	c3                   	ret    

00000beb <uthread_yield>:

void uthread_yield()
{
 beb:	55                   	push   %ebp
 bec:	89 e5                	mov    %esp,%ebp
 bee:	83 ec 18             	sub    $0x18,%esp
	//store registers on stack
	asm("pusha");
 bf1:	60                   	pusha  
	alarm(0);
 bf2:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 bf9:	e8 3a f8 ff ff       	call   438 <alarm>
	ttable[c_thread].state = T_RUNNABLE;
 bfe:	a1 4c 14 00 00       	mov    0x144c,%eax
 c03:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c09:	05 70 16 00 00       	add    $0x1670,%eax
 c0e:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
	//change current thread
	uthread_switch();
 c14:	e8 fc fe ff ff       	call   b15 <uthread_switch>
	asm("popa");
 c19:	61                   	popa   
}
 c1a:	c9                   	leave  
 c1b:	c3                   	ret    

00000c1c <uthread_awake>:

// task 2.5

void uthread_awake()
{
 c1c:	55                   	push   %ebp
 c1d:	89 e5                	mov    %esp,%ebp
 c1f:	83 ec 10             	sub    $0x10,%esp
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 c22:	c7 45 fc 00 00 00 00 	movl   $0x0,-0x4(%ebp)
 c29:	eb 2c                	jmp    c57 <uthread_awake+0x3b>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
 c2b:	a1 4c 14 00 00       	mov    0x144c,%eax
 c30:	6b d0 46             	imul   $0x46,%eax,%edx
 c33:	8b 45 fc             	mov    -0x4(%ebp),%eax
 c36:	01 d0                	add    %edx,%eax
 c38:	83 c0 04             	add    $0x4,%eax
 c3b:	8b 04 85 64 16 00 00 	mov    0x1664(,%eax,4),%eax
 c42:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c48:	05 70 16 00 00       	add    $0x1670,%eax
 c4d:	c7 00 02 00 00 00    	movl   $0x2,(%eax)
// task 2.5

void uthread_awake()
{
	int i;
	for (i = 0; i < ttable[c_thread].wait_num; i++)
 c53:	83 45 fc 01          	addl   $0x1,-0x4(%ebp)
 c57:	a1 4c 14 00 00       	mov    0x144c,%eax
 c5c:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c62:	05 70 17 00 00       	add    $0x1770,%eax
 c67:	8b 40 04             	mov    0x4(%eax),%eax
 c6a:	3b 45 fc             	cmp    -0x4(%ebp),%eax
 c6d:	7f bc                	jg     c2b <uthread_awake+0xf>
		ttable[ttable[c_thread].waiting[i]].state = T_RUNNABLE;
}
 c6f:	c9                   	leave  
 c70:	c3                   	ret    

00000c71 <uthread_exit>:

void uthread_exit()
{
 c71:	55                   	push   %ebp
 c72:	89 e5                	mov    %esp,%ebp
 c74:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 c77:	60                   	pusha  
	alarm(0);
 c78:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 c7f:	e8 b4 f7 ff ff       	call   438 <alarm>
	asm("popa");
 c84:	61                   	popa   
	ttable[c_thread].state = T_FREE;
 c85:	a1 4c 14 00 00       	mov    0x144c,%eax
 c8a:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 c90:	05 70 16 00 00       	add    $0x1670,%eax
 c95:	c7 00 00 00 00 00    	movl   $0x0,(%eax)
	if (ttable[c_thread].tid != 0)
 c9b:	a1 4c 14 00 00       	mov    0x144c,%eax
 ca0:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 ca6:	05 60 16 00 00       	add    $0x1660,%eax
 cab:	8b 00                	mov    (%eax),%eax
 cad:	85 c0                	test   %eax,%eax
 caf:	74 1d                	je     cce <uthread_exit+0x5d>
		free(ttable[c_thread].stack);
 cb1:	a1 4c 14 00 00       	mov    0x144c,%eax
 cb6:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 cbc:	05 60 16 00 00       	add    $0x1660,%eax
 cc1:	8b 40 0c             	mov    0xc(%eax),%eax
 cc4:	89 04 24             	mov    %eax,(%esp)
 cc7:	e8 10 fa ff ff       	call   6dc <free>
 ccc:	eb 05                	jmp    cd3 <uthread_exit+0x62>
	else
		safe_exit();
 cce:	e8 fa fd ff ff       	call   acd <safe_exit>
	uthread_awake();
 cd3:	e8 44 ff ff ff       	call   c1c <uthread_awake>
	uthread_switch();
 cd8:	e8 38 fe ff ff       	call   b15 <uthread_switch>
	asm("popa");
 cdd:	61                   	popa   
}
 cde:	c9                   	leave  
 cdf:	c3                   	ret    

00000ce0 <uthread_self>:

// task 2.6

int uthread_self()
{
 ce0:	55                   	push   %ebp
 ce1:	89 e5                	mov    %esp,%ebp
	return c_thread;
 ce3:	a1 4c 14 00 00       	mov    0x144c,%eax
}
 ce8:	5d                   	pop    %ebp
 ce9:	c3                   	ret    

00000cea <uthread_sleep>:

// task 2.7

void uthread_sleep()
{
 cea:	55                   	push   %ebp
 ceb:	89 e5                	mov    %esp,%ebp
 ced:	83 ec 18             	sub    $0x18,%esp
	asm("pusha");
 cf0:	60                   	pusha  
	alarm(0);
 cf1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 cf8:	e8 3b f7 ff ff       	call   438 <alarm>
	ttable[c_thread].state = T_SLEEPING;
 cfd:	a1 4c 14 00 00       	mov    0x144c,%eax
 d02:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d08:	05 70 16 00 00       	add    $0x1670,%eax
 d0d:	c7 00 03 00 00 00    	movl   $0x3,(%eax)
	uthread_switch();
 d13:	e8 fd fd ff ff       	call   b15 <uthread_switch>
	asm("popa");
 d18:	61                   	popa   
}
 d19:	c9                   	leave  
 d1a:	c3                   	ret    

00000d1b <uthread_join>:

int uthread_join(int tid)
{
 d1b:	55                   	push   %ebp
 d1c:	89 e5                	mov    %esp,%ebp
 d1e:	53                   	push   %ebx
 d1f:	83 ec 24             	sub    $0x24,%esp

	int ticks;
	asm("pusha");
 d22:	60                   	pusha  
	ticks = getTicks();
 d23:	e8 18 f7 ff ff       	call   440 <getTicks>
 d28:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 d2b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 d32:	e8 01 f7 ff ff       	call   438 <alarm>
	asm("popa");
 d37:	61                   	popa   
	if (ttable[tid].state != T_FREE)
 d38:	8b 45 08             	mov    0x8(%ebp),%eax
 d3b:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d41:	05 70 16 00 00       	add    $0x1670,%eax
 d46:	8b 00                	mov    (%eax),%eax
 d48:	85 c0                	test   %eax,%eax
 d4a:	74 5e                	je     daa <uthread_join+0x8f>
	{
		//adding current thread to tid waiting list and going to sleep.
		ttable[tid].waiting[ttable[tid].wait_num++] = ttable[c_thread].tid;
 d4c:	8b 45 08             	mov    0x8(%ebp),%eax
 d4f:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d55:	05 10 01 00 00       	add    $0x110,%eax
 d5a:	05 60 16 00 00       	add    $0x1660,%eax
 d5f:	8d 48 04             	lea    0x4(%eax),%ecx
 d62:	8b 45 08             	mov    0x8(%ebp),%eax
 d65:	69 c0 18 01 00 00    	imul   $0x118,%eax,%eax
 d6b:	05 70 17 00 00       	add    $0x1770,%eax
 d70:	8b 40 04             	mov    0x4(%eax),%eax
 d73:	8b 15 4c 14 00 00    	mov    0x144c,%edx
 d79:	69 d2 18 01 00 00    	imul   $0x118,%edx,%edx
 d7f:	81 c2 60 16 00 00    	add    $0x1660,%edx
 d85:	8b 12                	mov    (%edx),%edx
 d87:	8b 5d 08             	mov    0x8(%ebp),%ebx
 d8a:	6b db 46             	imul   $0x46,%ebx,%ebx
 d8d:	01 c3                	add    %eax,%ebx
 d8f:	83 c3 04             	add    $0x4,%ebx
 d92:	89 14 9d 64 16 00 00 	mov    %edx,0x1664(,%ebx,4)
 d99:	83 c0 01             	add    $0x1,%eax
 d9c:	89 01                	mov    %eax,(%ecx)
		uthread_sleep();
 d9e:	e8 47 ff ff ff       	call   cea <uthread_sleep>
		return 0;
 da3:	b8 00 00 00 00       	mov    $0x0,%eax
 da8:	eb 12                	jmp    dbc <uthread_join+0xa1>
	}
	asm("pusha");
 daa:	60                   	pusha  
	alarm(ticks);
 dab:	8b 45 f4             	mov    -0xc(%ebp),%eax
 dae:	89 04 24             	mov    %eax,(%esp)
 db1:	e8 82 f6 ff ff       	call   438 <alarm>
	asm("popa");
 db6:	61                   	popa   
	return -1;
 db7:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
}
 dbc:	83 c4 24             	add    $0x24,%esp
 dbf:	5b                   	pop    %ebx
 dc0:	5d                   	pop    %ebp
 dc1:	c3                   	ret    

00000dc2 <queue_init>:

void queue_init(struct tqueue *q)
{
 dc2:	55                   	push   %ebp
 dc3:	89 e5                	mov    %esp,%ebp
	q->head = 0;
 dc5:	8b 45 08             	mov    0x8(%ebp),%eax
 dc8:	c7 80 00 01 00 00 00 	movl   $0x0,0x100(%eax)
 dcf:	00 00 00 
	q->tail = 0;
 dd2:	8b 45 08             	mov    0x8(%ebp),%eax
 dd5:	c7 80 04 01 00 00 00 	movl   $0x0,0x104(%eax)
 ddc:	00 00 00 
}
 ddf:	5d                   	pop    %ebp
 de0:	c3                   	ret    

00000de1 <dequeue>:

struct uthread* dequeue(struct binary_semaphore* semaphore)
{
 de1:	55                   	push   %ebp
 de2:	89 e5                	mov    %esp,%ebp
 de4:	57                   	push   %edi
 de5:	56                   	push   %esi
 de6:	53                   	push   %ebx
	if (semaphore->queue->head == semaphore->queue->tail)
 de7:	8b 45 08             	mov    0x8(%ebp),%eax
 dea:	8b 00                	mov    (%eax),%eax
 dec:	8b 90 00 01 00 00    	mov    0x100(%eax),%edx
 df2:	8b 45 08             	mov    0x8(%ebp),%eax
 df5:	8b 00                	mov    (%eax),%eax
 df7:	8b 80 04 01 00 00    	mov    0x104(%eax),%eax
 dfd:	39 c2                	cmp    %eax,%edx
 dff:	75 07                	jne    e08 <dequeue+0x27>
		return 0;
 e01:	b9 00 00 00 00       	mov    $0x0,%ecx
 e06:	eb 31                	jmp    e39 <dequeue+0x58>
	return semaphore->queue->uthreads[semaphore->queue->tail++ % MAX_THREAD];
 e08:	8b 45 08             	mov    0x8(%ebp),%eax
 e0b:	8b 18                	mov    (%eax),%ebx
 e0d:	8b 45 08             	mov    0x8(%ebp),%eax
 e10:	8b 10                	mov    (%eax),%edx
 e12:	8b 82 04 01 00 00    	mov    0x104(%edx),%eax
 e18:	89 c1                	mov    %eax,%ecx
 e1a:	c1 f9 1f             	sar    $0x1f,%ecx
 e1d:	c1 e9 1a             	shr    $0x1a,%ecx
 e20:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 e23:	83 e6 3f             	and    $0x3f,%esi
 e26:	89 f7                	mov    %esi,%edi
 e28:	29 cf                	sub    %ecx,%edi
 e2a:	89 f9                	mov    %edi,%ecx
 e2c:	8b 0c 8b             	mov    (%ebx,%ecx,4),%ecx
 e2f:	83 c0 01             	add    $0x1,%eax
 e32:	89 82 04 01 00 00    	mov    %eax,0x104(%edx)
 e38:	90                   	nop
 e39:	89 c8                	mov    %ecx,%eax
}
 e3b:	5b                   	pop    %ebx
 e3c:	5e                   	pop    %esi
 e3d:	5f                   	pop    %edi
 e3e:	5d                   	pop    %ebp
 e3f:	c3                   	ret    

00000e40 <enqueue>:

void enqueue(struct binary_semaphore* semaphore)
{
 e40:	55                   	push   %ebp
 e41:	89 e5                	mov    %esp,%ebp
 e43:	57                   	push   %edi
 e44:	56                   	push   %esi
 e45:	53                   	push   %ebx
	semaphore->queue->uthreads[semaphore->queue->head++ % MAX_THREAD] = &ttable[c_thread];
 e46:	8b 45 08             	mov    0x8(%ebp),%eax
 e49:	8b 18                	mov    (%eax),%ebx
 e4b:	8b 45 08             	mov    0x8(%ebp),%eax
 e4e:	8b 10                	mov    (%eax),%edx
 e50:	8b 82 00 01 00 00    	mov    0x100(%edx),%eax
 e56:	89 c1                	mov    %eax,%ecx
 e58:	c1 f9 1f             	sar    $0x1f,%ecx
 e5b:	c1 e9 1a             	shr    $0x1a,%ecx
 e5e:	8d 34 08             	lea    (%eax,%ecx,1),%esi
 e61:	83 e6 3f             	and    $0x3f,%esi
 e64:	89 f7                	mov    %esi,%edi
 e66:	29 cf                	sub    %ecx,%edi
 e68:	89 f9                	mov    %edi,%ecx
 e6a:	8b 35 4c 14 00 00    	mov    0x144c,%esi
 e70:	69 f6 18 01 00 00    	imul   $0x118,%esi,%esi
 e76:	81 c6 60 16 00 00    	add    $0x1660,%esi
 e7c:	89 34 8b             	mov    %esi,(%ebx,%ecx,4)
 e7f:	83 c0 01             	add    $0x1,%eax
 e82:	89 82 00 01 00 00    	mov    %eax,0x100(%edx)
}
 e88:	5b                   	pop    %ebx
 e89:	5e                   	pop    %esi
 e8a:	5f                   	pop    %edi
 e8b:	5d                   	pop    %ebp
 e8c:	c3                   	ret    

00000e8d <binary_semaphore_init>:

void binary_semaphore_init(struct binary_semaphore* semaphore, int value)
{
 e8d:	55                   	push   %ebp
 e8e:	89 e5                	mov    %esp,%ebp
 e90:	83 ec 18             	sub    $0x18,%esp
	semaphore->queue = malloc(sizeof(struct tqueue));
 e93:	c7 04 24 08 01 00 00 	movl   $0x108,(%esp)
 e9a:	e8 76 f9 ff ff       	call   815 <malloc>
 e9f:	8b 55 08             	mov    0x8(%ebp),%edx
 ea2:	89 02                	mov    %eax,(%edx)
	if (!value)
 ea4:	83 7d 0c 00          	cmpl   $0x0,0xc(%ebp)
 ea8:	75 0c                	jne    eb6 <binary_semaphore_init+0x29>
		semaphore->state = S_LOCKED;
 eaa:	8b 45 08             	mov    0x8(%ebp),%eax
 ead:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
 eb4:	eb 0a                	jmp    ec0 <binary_semaphore_init+0x33>
	else
		semaphore->state = S_FREE;
 eb6:	8b 45 08             	mov    0x8(%ebp),%eax
 eb9:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
}
 ec0:	c9                   	leave  
 ec1:	c3                   	ret    

00000ec2 <binary_semaphore_down>:
void binary_semaphore_down(struct binary_semaphore* semaphore)
{
 ec2:	55                   	push   %ebp
 ec3:	89 e5                	mov    %esp,%ebp
 ec5:	83 ec 28             	sub    $0x28,%esp
	//store amount of ticks left and prevent scheduler from switching
	int ticks;
	asm("pusha");
 ec8:	60                   	pusha  
	ticks = getTicks();
 ec9:	e8 72 f5 ff ff       	call   440 <getTicks>
 ece:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 ed1:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 ed8:	e8 5b f5 ff ff       	call   438 <alarm>
	asm("popa");
 edd:	61                   	popa   
	if (semaphore->state == S_LOCKED)
 ede:	8b 45 08             	mov    0x8(%ebp),%eax
 ee1:	8b 40 04             	mov    0x4(%eax),%eax
 ee4:	83 f8 01             	cmp    $0x1,%eax
 ee7:	75 1c                	jne    f05 <binary_semaphore_down+0x43>
	{
		enqueue(semaphore);
 ee9:	8b 45 08             	mov    0x8(%ebp),%eax
 eec:	89 04 24             	mov    %eax,(%esp)
 eef:	e8 4c ff ff ff       	call   e40 <enqueue>
		uthread_sleep();
 ef4:	e8 f1 fd ff ff       	call   cea <uthread_sleep>
		alarm(0);
 ef9:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 f00:	e8 33 f5 ff ff       	call   438 <alarm>
	}
	semaphore->state = S_LOCKED;
 f05:	8b 45 08             	mov    0x8(%ebp),%eax
 f08:	c7 40 04 01 00 00 00 	movl   $0x1,0x4(%eax)
	//allow the thread to run its remaining time
	alarm(ticks);
 f0f:	8b 45 f4             	mov    -0xc(%ebp),%eax
 f12:	89 04 24             	mov    %eax,(%esp)
 f15:	e8 1e f5 ff ff       	call   438 <alarm>

}
 f1a:	c9                   	leave  
 f1b:	c3                   	ret    

00000f1c <binary_semaphore_up>:
void binary_semaphore_up(struct binary_semaphore* semaphore)
{
 f1c:	55                   	push   %ebp
 f1d:	89 e5                	mov    %esp,%ebp
 f1f:	83 ec 28             	sub    $0x28,%esp
	int ticks;
	struct uthread *next;
	asm("pusha");
 f22:	60                   	pusha  
	ticks = getTicks();
 f23:	e8 18 f5 ff ff       	call   440 <getTicks>
 f28:	89 45 f4             	mov    %eax,-0xc(%ebp)
	alarm(0);
 f2b:	c7 04 24 00 00 00 00 	movl   $0x0,(%esp)
 f32:	e8 01 f5 ff ff       	call   438 <alarm>
	asm("popa");
 f37:	61                   	popa   


	if ((next = dequeue(semaphore)) == 0)
 f38:	8b 45 08             	mov    0x8(%ebp),%eax
 f3b:	89 04 24             	mov    %eax,(%esp)
 f3e:	e8 9e fe ff ff       	call   de1 <dequeue>
 f43:	89 45 f0             	mov    %eax,-0x10(%ebp)
 f46:	83 7d f0 00          	cmpl   $0x0,-0x10(%ebp)
 f4a:	75 19                	jne    f65 <binary_semaphore_up+0x49>
	{
		//no thread is waiting. release semaphore and restore alarm
		semaphore->state = S_FREE;
 f4c:	8b 45 08             	mov    0x8(%ebp),%eax
 f4f:	c7 40 04 00 00 00 00 	movl   $0x0,0x4(%eax)
		asm("pusha");
 f56:	60                   	pusha  
		alarm(ticks);
 f57:	8b 45 f4             	mov    -0xc(%ebp),%eax
 f5a:	89 04 24             	mov    %eax,(%esp)
 f5d:	e8 d6 f4 ff ff       	call   438 <alarm>
		asm("popa");
 f62:	61                   	popa   
 f63:	eb 0f                	jmp    f74 <binary_semaphore_up+0x58>
	}
	else
	{
		//threads are waiting. wake up the next thread and yield.
		next->state = T_RUNNABLE;
 f65:	8b 45 f0             	mov    -0x10(%ebp),%eax
 f68:	c7 40 10 02 00 00 00 	movl   $0x2,0x10(%eax)
		uthread_yield();
 f6f:	e8 77 fc ff ff       	call   beb <uthread_yield>
	}
}
 f74:	c9                   	leave  
 f75:	c3                   	ret    
